package spring.boot.adminx.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import spring.boot.adminx.service.TProvinceService;

import java.util.*;

@Controller
@RequestMapping("/data/table")
public class DataTableController {

    @Autowired
    private TProvinceService tProvinceService;

    @GetMapping("list")
    public String list(Model model){
        model.addAttribute("provinceList", tProvinceService.list());
        return "data/list";
    }

    @GetMapping("data")
    @ResponseBody
    public Map data(int page,int limit){
        List<Map> list = new ArrayList<>();
        for (int i = (page-1)*10+1; i <= (page-1)*10+limit; i++) {
            Map map = new HashMap(8);
            map.put("id",i);
            map.put("name","姓名--"+i);
            map.put("sex", Math.abs(new Random().nextInt()%2));
            map.put("time",new Date());
            list.add(map);
        }

        Map map = new HashMap(8);
        map.put("code",0);
        map.put("msg","");
        map.put("count",1000);
        map.put("data",list);
        return map;
    }

}
